<template>
<div>
<HomePanel title="热门品牌" subTitle="国际经典 品质保证" ref="target">
       <template v-slot:right>
         <!-- 点击index等于0，如果index等于0则加上禁用类名 -->
      <a href="javascript:;" class="iconfont icon-angle-left prev" @click="index=0" :class="{'disabled':index===0}"></a>
      <!-- 点击index等于1，如果index等于1则加上禁用类名 -->
      <a href="javascript:;" class="iconfont icon-angle-right next" ref="" @click="index=1"  :class="{'disabled':index===1}"></a>
    </template>
    <div class="box" ref="box">
      <!-- 如果index等于true【1】就加上向x轴移动-50%的类名，否则加上x轴0%的类名 -->
      <ul class="list" :class="index?'transfrom':'transfroms'" v-if="goods.length" >
        <li v-for="i in goods" :key="i.id">
          <RouterLink to="/">
            <img v-lazy="i.picture" alt="">
          </RouterLink>
        </li>
      </ul>
      <div class="abcd" v-else>
         <XtxSkeleton v-for="i in 5" :key="i" width="240px" height="100%" bg="#e4e4e4"></XtxSkeleton>
      </div>

    </div>
</HomePanel>
</div>
</template>
<script>
// 引入懒加载的函数
import { useLazyData } from '@/hooks'
// 引入获取品牌的api
import { homebrand } from '@/api/home'
// 引入面板组件
import HomePanel from './home-panel'
import { ref } from 'vue'
import XtxSkeleton from '@/components/library/xtx-skeleton.vue'
export default {
  name: 'HomeBrand',
  components: { HomePanel, XtxSkeleton },
  setup () {
    const index = ref(0)
    const { goods, target } = useLazyData(homebrand)
    return { goods, target, index }
  }
}
</script>

<style scoped lang='less'>
.abcd{
  width: 100%;
  display: flex;
  height: 305px;
  justify-content: space-between;
}
.home-panel {
  background:#f5f5f5
}
.iconfont {
  width: 20px;
  height: 20px;
  background: #ccc;
  color: #fff;
  display: inline-block;
  text-align: center;
  margin-left: 5px;
  background: @xtxColor;
  &::before {
    font-size: 12px;
    position: relative;
    top: -2px
  }
  &.disabled {
    background: #ccc;
    cursor: not-allowed;
  }
}
.box {
  display: flex;
  width: 100%;
  height: 345px;
  overflow: hidden;
  padding-bottom: 40px;
  .transfrom{
      transform: translateX(-50%);
  }
  .transfroms{
      transform: translateX(0);
  }
  .list {
    width: 200%;
    display: flex;
    transition: all 1s;
    li {
      margin-right: 10px;
      width: 240px;
      &:nth-child(5n) {
        margin-right: 0;
      }
      img {
        width: 240px;
        height: 305px;
      }
    }
  }
}
</style>
